package com.love_weinuo.ui.adapter;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.love_weinuo.R;
import com.love_weinuo.bean.EarCallbackBean;
import com.love_weinuo.databinding.ItemMyCommissionBinding;

import java.util.List;

/**
 * Created by SensYang on 2019/03/01 11:15
 */

public class MyCommissionAdapter extends RecyclerView.Adapter<BaseRecyclerViewHolder> {
    private List<EarCallbackBean.ResultEntity.ResEntity> strings;
    private Context mcontext;
    OnItemClickListener mOnItemClickLitener;

    public MyCommissionAdapter(Context context, List<EarCallbackBean.ResultEntity.ResEntity> strings) {
        this.mcontext = context;
        this.strings = strings;
    }

    @Override
    public BaseRecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        ItemMyCommissionBinding functionBinding = DataBindingUtil.inflate(LayoutInflater.from(mcontext), R.layout.item_my_commission, parent, false);
        functionBinding.setAdapter(this);
        return new TourViewHolder(functionBinding);
    }

    @Override
    public void onBindViewHolder(final BaseRecyclerViewHolder holder, final int position) {
        holder.bindData(strings.get(position));
        TourViewHolder tv = (TourViewHolder) holder;

        if (mOnItemClickLitener != null) {
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int pos = holder.getLayoutPosition();
                    mOnItemClickLitener.onItemClick(holder.itemView, pos);
                }
            });

            holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    int pos = holder.getLayoutPosition();
                    mOnItemClickLitener.onItemLongClick(holder.itemView, pos);
                    return false;
                }
            });
        }
    }

    public void setOnItemClickLitener(OnItemClickListener mOnItemClickLitener) {
        this.mOnItemClickLitener = mOnItemClickLitener;
    }

    @Override
    public int getItemCount() {
        return strings.size();
    }

    public class TourViewHolder extends BaseRecyclerViewHolder<EarCallbackBean.ResultEntity.ResEntity> {
        ItemMyCommissionBinding functionBinding;

        public TourViewHolder(ItemMyCommissionBinding dataBinding) {
            super(dataBinding.getRoot());
            functionBinding = dataBinding;
        }

        @Override
        public void bindData(EarCallbackBean.ResultEntity.ResEntity data) {
            functionBinding.setBean(data);
        }
    }

    @Override
    public int getItemViewType(int position) {
        return strings.size();
    }


    public void toNext(View view, EarCallbackBean.ResultEntity.ResEntity t) {

    }
}